package com.ae.shield.common.events;

import com.ae.shield.ModLib;
import com.ae.shield.common.items.ItemList;
import net.minecraft.entity.merchant.villager.VillagerProfession;
import net.minecraft.entity.merchant.villager.VillagerTrades;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.item.MerchantOffer;
import net.minecraftforge.event.village.VillagerTradesEvent;
import net.minecraftforge.event.village.WandererTradesEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;

import java.util.List;

import static net.minecraft.entity.merchant.villager.VillagerProfession.LIBRARIAN;

@Mod.EventBusSubscriber(modid = ModLib.MOD_ID, bus = Mod.EventBusSubscriber.Bus.FORGE)
public class AddTradesEvent {
    @SubscribeEvent
    public static void AddWandererTradesEvent(WandererTradesEvent event) {
        event.getRareTrades().add((trader, random) -> new MerchantOffer(
                new ItemStack(Items.EMERALD, 50 + random.nextInt(14)),
                new ItemStack(Items.TOTEM_OF_UNDYING),
                new ItemStack(ItemList.TRANSFORMED_TOTEM.get()),
                1,
                150,
                0.2f));
    }

    @SubscribeEvent
    public static void AddVillagerTradesEvent(VillagerTradesEvent event) {
        VillagerProfession type = event.getType();
        if (type == LIBRARIAN) {
            List<VillagerTrades.ITrade> trades = event.getTrades().get(4);
            trades.add((trader, random) -> new MerchantOffer(
                    new ItemStack(Items.GHAST_TEAR, 10),
                    new ItemStack(Items.WRITABLE_BOOK),
                    new ItemStack(ItemList.ROOKIE_MAGIC_SPELL.get()),
                    1,
                    5,
                    0.2f)
            );
        }
    }
}
